package com.huizhonglm.diap.presenters.tab;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.model.user.IntegralParams;
import com.huizhonglm.diap.api.model.user.IntegralResponse;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.tab.iView.TabhostMeIView;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:53
 */
public class TabhostMePresenter extends BasePresenter {

    private TabhostMeIView iView;

    public TabhostMePresenter(TabhostMeIView iView) {
        this.iView = iView;
    }

    public void refreshIntegral(String userId){
        IntegralParams params = new IntegralParams();
        params.userId = userId;
        API.http().post("refreshIntegral", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    IntegralResponse resp = JSON.parseObject(result, IntegralResponse.class);
                    iView.onRefIntegralSuccess(resp);
                } else {
                    iView.onRefIntegralFailure();
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onRefIntegralFailure();
            }
        });
    }
}
